package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {
	
	private static Connection conn;
	
	static String URL= "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
	static String USER= "root";
	static	String PASSWORD= "123456";
	static{
	     //1.加载驱动程序
	     try {
//		     Class.forName("com.mysql.jdbc.Driver");    //mysql 7 5
		     Class.forName("com.mysql.cj.jdbc.Driver"); //mysql 8
			 conn = DriverManager.getConnection(URL, USER, PASSWORD);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection(){
		return conn;
	}
	
//	public static Connection newConnection() {
//		try {
//			return DriverManager.getConnection(URL, USER, PASSWORD);
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		return null;
//	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 100; i++) {
			Connection conn = getConnection();
			System.out.println(conn);
		}
	}
}
